<template>

  <div class="video-container">
    <div :style="fixStyle" class="filter"></div>
    <video :style="fixStyle" autoplay loop class="fillWidth" v-on:canplay="canplay" muted>
      <source :src="PATH_TO_MP4" type="video/mp4"/>
      浏览器不支持 video 标签，建议升级浏览器。
      <source :src="PATH_TO_WEBM" type="video/webm"/>
      浏览器不支持 video 标签，建议升级浏览器。
    </video>
    <div class="poster hidden" v-if="!vedioCanPlay">
      <img :style="fixStyle" :src="PATH_TO_JPEG" alt="背景">
    </div>
  </div>
</template>

<script>
import ChartCard from '@/components/ChartCard'
import ACol from 'ant-design-vue/es/grid/Col'
import ATooltip from 'ant-design-vue/es/tooltip/Tooltip'
import MiniArea from '@/components/chart/MiniArea'
import MiniBar from '@/components/chart/MiniBar'
import MiniProgress from '@/components/chart/MiniProgress'
import RankList from '@/components/chart/RankList'
import Bar from '@/components/chart/Bar'
import LineChartMultid from '@/components/chart/LineChartMultid'
import HeadInfo from '@/components/tools/HeadInfo.vue'

import Trend from '@/components/Trend'
import { getLoginfo, getVisitInfo } from '@/api/api'
import { getAction, postAction } from '@/api/manage'
import mp4Path from "../../assets/video/ysxy.mp4"
import webmPath from "../../assets/video/ysxy.webm"
import jpegPath from "../../assets/蒲公英背景图-默认背景图.jpg"

export default {
  name: 'LoginBackgroundVideo',
  components: {},
  data() {
    return {
      vedioCanPlay: false,
      fixStyle: '',
      PATH_TO_MP4: '',
      PATH_TO_WEBM: '',
      PATH_TO_JPEG: '',
    }
  },
  created() {
    this.PATH_TO_JPEG = jpegPath
    this.PATH_TO_MP4 = mp4Path
    this.PATH_TO_WEBM = webmPath
  },
  mounted () {
    document.body.classList.add('userLayout')
    window.onresize = () => {
      const windowWidth = document.body.clientWidth
      const windowHeight = document.body.clientHeight
      const windowAspectRatio = windowHeight / windowWidth
      let videoWidth
      let videoHeight
      if (windowAspectRatio < 0.5625) {
        videoWidth = windowWidth
        videoHeight = videoWidth * 0.5625
        this.fixStyle = {
          height: windowWidth * 0.5625 + 'px',
          width: windowWidth + 'px',
          'margin-bottom': (windowHeight - videoHeight) / 2 + 'px',
          'margin-left': 'initial'
        }
      } else {
        videoHeight = windowHeight
        videoWidth = videoHeight / 0.5625
        this.fixStyle = {
          height: windowHeight + 'px',
          width: windowHeight / 0.5625 + 'px',
          'margin-left': (windowWidth - videoWidth) / 2 + 'px',
          'margin-bottom': 'initial'
        }
      }
    }
    window.onresize()
  },
  methods: {
    canplay() {
      this.vedioCanPlay = true
      console.log(this.vedioCanPlay);
    },
  }
}
</script>

<style lang='less' scoped>

.video-container .poster img,
.video-container video {
  z-index: 0;
  position: absolute;
}

.video-container .filter {
  z-index: 1;
  position: absolute;
  background: rgba(0, 0, 0, 0.4);
}

</style>